<template>
  <div class="card-record">
    <div class="mescroll"  ref="mescroll"> 
      <tab class="list-tab" 
          custom-bar-width="1.7rem"
          bar-active-color="#172F6D"
          >
        <tab-item selected @on-item-click="onItemClick(0)">全部</tab-item>
        <tab-item @on-item-click="onItemClick(1)">办卡记录</tab-item>
        <tab-item @on-item-click="onItemClick(2)">打卡记录</tab-item>
      </tab>
      <div class="list">
        <div v-for="(item,index) in lists" :key="index" class="list-item" @click="jumpReview(item.type,item.id)">
          <div class="type">
            <p class="title">「{{item.type_txt}}」{{item.txt}}</p>
            <p class="time">{{item.create_time}}</p>
          </div>
          <div class="num">
            <p class="title">{{item.num}}次</p>
            <p class="time">剩余{{item.after_num}}次</p>          
          </div>
          <div class="is-comment">
            <p v-if="item.review==0"  v-show="item.type==2">待点评</p>  
            <p v-else  v-show="item.type==2">已点评</p>   
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {cardlog} from '@/api/api'
  import MeScroll from 'mescroll.js'
  import 'mescroll.js/mescroll.min.css'
  import { Tab, TabItem } from 'vux'

  export default {
    components: {
      Tab,
      TabItem,
    },
    data () {
      return {
        lists:[],
        is_list: ['true'],
        types:0,
        mescroll: null, //mescroll实例对象
      }
    },
    created () {
    },
    mounted () {
      this.mescroll = new MeScroll(this.$refs.mescroll, { 
        up: {
          callback: this.upCallback
        }
      })
    },
    methods: {
      router (path) {
        this.$router.push(path)
      },
      upCallback (page) {
        cardlog(this.types,0,page.num, page.size).then((res) => {
          if (page.num == 1){
            this.lists = []
          }
          if(res.data.info == null){
            this.mescroll.endErr()
            return
          }
          this.$nextTick(() => {
            this.mescroll.endSuccess(res.data.info);
          })
          this.lists = this.lists.concat(res.data.info)
        }).catch((err) => {
          console.dir(err)
          this.mescroll.endErr()
        })
      },
      onItemClick (index) {
        this.types=index
        this.mescroll.resetUpScroll()
      },
      jumpReview(type,id){
        if(type==2){
          this.router({path: './storeComment',query:{id:id}})
        }
      }
    }
  }
</script>

<style lang="stylus" scoped>
.card-record
  width 100%
  height 100vh
  overflow hidden
  background-color #fff
  .list-tab
    padding-top 5rem
    border-bottom 1rem solid #f5f5f5
    .vux-tab-container
      height 5rem
      .vux-tab-item.vux-tab-selected
        font-weight bold
      .vux-tab-item
        color #000
        font-size 1.6rem
        font-weight 400
  .mescroll
    position fixed
    top 0
    bottom 0
    height auto
    width 100vw
    overflow-x hidden
    .top-img
      float left
    .search
      float left
      width 92%
      margin-left 4%
      text-align center
      background-color #fff
      height 4.5rem
      line-height 4.5rem
      margin-top -2.25rem
      margin-bottom 1rem
      img
        display inline-block
        vertical-align middle
        width 1.6rem
      span
        display inline-block
        vertical-align middle
        font-size 1.3rem
        color #172F6D
        margin-left .5rem
  .list
    .list-item
      padding 1.5rem
      display flex
      border-bottom 1px solid #e6e6e6
      &:last-child
        border none
      .title
        color #333
        font-size 1.5rem
        font-weight bold
        position relative
        left -.8rem
      .time
        color #999
        font-size 1.2rem
      .type
        flex 2
      .num
        flex 1
        text-align right
      .is-comment
        flex 1
        color #172F6D
        font-size 1.3rem
        line-height 4rem
        height 4rem
        text-align right
</style>
